package na.learn.java.combinatorics;

public abstract class AbstractPermutator implements Permutator{
	
	protected  String swap(String source, int level, int count) {

		if (level == count)
			return source;

		char ch1 = source.charAt(level - 1);
		StringBuffer tmpStr = new StringBuffer(source);//.substring(0,level);
		tmpStr.setCharAt(level - 1, tmpStr.charAt(count - 1));
		tmpStr.setCharAt(count - 1, ch1);

		return tmpStr.toString();
	}

	protected int countSpaces(String source) {
		int counter = 0;
		StringBuffer buffer = new StringBuffer(source);
		while (buffer.length() != 0 && buffer.indexOf(" ") != -1) {
			buffer.delete(0, buffer.indexOf(" ") + 1);
			counter++;

		}
		return counter;
	}

}
